<template>
	<view>
		<view v-if="loading">
			<loading></loading>
		</view>
		<view v-else class="container">
			<view class="topTitle">
				<text @tap="toLog">观看记录</text>
			</view>
			<view class="course-body"  v-if="list.length > 0">
				<view class="course-view"  v-for="(item,index) in list" :index="index" :key="index"  @click="clickDetail(item)">
					<view class="imgView">
						<image :src="item.imgUrl" mode="heightFix"></image>
					</view>
					<view class="textView">
						<text>{{item.knowledgeName}}</text>
					</view>
				</view>
			</view>
			<view class=""  v-else>
				<isEmpty empty-text="暂无数据"></isEmpty>
			</view>
			<view class="load-more">
				<uni-icons v-if="loadShow" type="spinner-cycle" size="30"></uni-icons>
				<text  v-if="botShow">已经到底了</text>
			</view>
		</view>
	</view>
</template>

<script>
	import isEmpty from '@/components/isEmpty/isEmpty'
	import loading from '@/components/loading/loading'
	import { getCourseList,creatCourse } from '@/api/exam/activity'
	export default {
		data() {
			return {
				pageForm:{
					pageNo:1,
					pageSize:10
				}	,
				categoryId:null,
				list:[],
				activeData:null,
				isRefresh:false,
				startTime:null,
				loadShow:false,
				botShow:false,
				loading:true
			}
		},
		onLoad(e) {
			this.categoryId = e.categoryId
			this.getList()
			//uni.setNavigationBarTitle({ title: '新的标题' });
		},
		onReachBottom(){
			if(!this.botShow){
				this.loadShow = true
				this.pageForm.pageNo ++ ;
				this.getList()
			}
			
		},
		methods: {
			getList(){
				this.pageForm.categoryId = this.categoryId
				getCourseList(this.pageForm).then(res =>{
					if(res.data.list.length > 0){
						this.list.push(...res.data.list)
						this.loadShow = false
					}else{
						this.loadShow = false
						this.botShow = true
					}
					this.loading = false
				})
			},
			clickDetail(e){
				this.activeData = e
				this.$tab.navigateTo('/pages/course/courseDetail?courseId=' + e.id)
			},
			toLog(){
				this.$tab.navigateTo('/pages/course/courseLog')
			},
		}
	}
</script>

<style lang="scss">
	.container{
		width: calc(100vw - 60rpx);
		margin: 20rpx auto;
	}
	.topTitle{
		display: flex;
		flex-direction: row-reverse;
		padding: 18rpx;
		
	}
	.course-body{
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
		border-radius: 20rpx;
		.course-view{
			background-color: #fff;
			margin-top: 40rpx;
			border-radius: 10rpx;
			overflow: hidden;
			.imgView{
				width: 320rpx;
				height: 300rpx;
				image{
					height: auto;
					height: 300rpx;
				}
			}
			.textView{
				height: 88rpx;
				background-color: #fff;
				display: block;
				text-align: center;
				line-height: 88rpx;
			}
		}
	}
	.load-more{
		display: block;
		padding: 20px;
		margin: 0 auto;
		text-align: center;
	}
</style>